from python_ai.common.xcommon import sep
import tensorflow as tf
import numpy as np

# ATTENTION
# AttributeError: Tensor.graph is meaningless when eager execution is enabled.
tf.compat.v1.disable_eager_execution()

sep('init')
m, n = 10, 4
mat = tf.Variable(np.zeros((m, n)), dtype=tf.float64)
tens = 10 ** np.arange(n)
tens[0] = 0
for_cols = tf.Variable(tens, dtype=tf.float64)
series = np.arange(m) + 1
for_rows = tf.Variable(series, dtype=tf.float64)
print(f'mat: {mat}')
print(f'for_col: {for_cols}')
print(f'for_row: {for_rows}')

sep('the calc gram')
res_mat = mat + for_cols
res_mat = tf.transpose(res_mat) + tf.transpose(for_rows)
res_mat = tf.transpose(res_mat)
res_mat = tf.cast(res_mat, dtype=tf.int64)
print(f'mat: {res_mat}')

sep('the calc')
with tf.compat.v1.Session() as sess:
    sess.run(tf.compat.v1.global_variables_initializer())
    res = sess.run(res_mat)
    print(res)


